package cn.yunhe.dao.impl;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import cn.yunhe.dao.Bookdao;
import cn.yunhe.dao.Coursedao;
import cn.yunhe.dao.Userdao;
import cn.yunhe.entity.Book;
import cn.yunhe.entity.Course;
import cn.yunhe.entity.User;

public class CourseDaoImpl {
	String resource="Config.xml";
	InputStream inputstream;
	SqlSessionFactory ssf;
	public List<Course> FindAllCourse() throws IOException  {
		inputstream=Resources.getResourceAsStream(resource);
		ssf=new SqlSessionFactoryBuilder().build(inputstream);
		SqlSession sqlsession=ssf.openSession();
		Coursedao coursedao=sqlsession.getMapper(Coursedao.class);
		List<Course> courselist=coursedao.FindAllCourse();
		sqlsession.close();
		return courselist;
	}
	public List<Course> FindCourseByTeacher(String teacher) throws IOException  {
		inputstream=Resources.getResourceAsStream(resource);
		ssf=new SqlSessionFactoryBuilder().build(inputstream);
		SqlSession sqlsession=ssf.openSession();
		Coursedao coursedao=sqlsession.getMapper(Coursedao.class);
		List<Course> courselist=coursedao.FindCourseByTeacher(teacher);
		sqlsession.close();
		return courselist;
	}
	public Course FindCourseByCid(String cid) throws IOException  {
		inputstream=Resources.getResourceAsStream(resource);
		ssf=new SqlSessionFactoryBuilder().build(inputstream);
		SqlSession sqlsession=ssf.openSession();
		Coursedao coursedao=sqlsession.getMapper(Coursedao.class);
		Course course=coursedao.FindCourseByCid(cid);
		sqlsession.close();
		return course;
	}
	
}
